<template>
  <card class="box-card mb-20 inform-money-template">
    <div slot="header">
      <span>快递员版本控制</span>
      <submit-button class="float-right" ref="Submit" @submit="submit" text="保存"/>
    </div>
    <el-form :model="form" :rules="rules" ref="Form" label-width="100px" hide-required-asterisk>
      <row-col>
        <el-form-item label="版本：" prop="version">
          <el-input v-model.trim="form.version"></el-input>
        </el-form-item>
      </row-col>
    </el-form>
  </card>
</template>

<script>
  import {getUpdateVersionApi, editUpdateVersionApi} from '@/api/website/inform'

  export default {
    name: "Version",
    data() {
      return {
        form: {
          version: ''
        },
        rules: {
          version: {required: true, message: '请输入版本', trigger: 'blur'}
        }
      }
    },
    mounted() {
      this.getData()
    },
    methods: {
      getData() {
        getUpdateVersionApi().then(result => {
          this.form.version = result.resultParam.systemConfig.value
        })
      },
      submit() {
        this.$refs['Form'].validate((valid) => {
          if (!valid) return false;
          let data = {...this.form};
          this.$refs.Submit.start();
          editUpdateVersionApi(data).then(() => {
            this.$refs.Submit.stop();
            this.$emit('update');
          }).catch(() => {
            this.$refs.Submit.stop();
          })
        });
      }
    }
  }
</script>
